package com.example.backend.common.api;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

/**
 * 统一响应对象
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class R<T> {
    private Integer code;
    private String message;
    private T data;
    
    public static <T> R<T> ok() {
        return new R<>(200, "success", null);
    }
    
    public static <T> R<T> ok(T data) {
        return new R<>(200, "success", data);
    }
    
    public static <T> R<T> fail(String message) {
        return new R<>(500, message, null);
    }

    public static <T> R<T> fail(ResultCode resultCode) {
        return new R<>(resultCode.getCode(),resultCode.getMessage(),null);
    }
    public static <T> R<T> fail(Integer code, String message) {
        return new R<>(code, message, null);
    }
} 